﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class View_infoMessage : System.Web.UI.Page
{
    AccessDAO dao = new AccessDAO();
    protected void Page_Load(object sender, EventArgs e)
    {
        IsAdmin.Admin();
        if (!Page.IsPostBack)
        {
            Session["infoId"] = "";
            show();
        }
    }

    private void show()
    {
        int id = Convert.ToInt32(Session["newTypeId"].ToString());
        string sql = "select newMessInfo.name as typename,newMessage.id as id,newMessage.title,newMessage.newTime from newMessInfo,newMessage where newMessInfo.id=newMessage.messId and newMessInfo.id=" + id;
        DataSet ds = dao.getDs(sql);
        this.GridView1.DataSource = ds;
        this.GridView1.DataBind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
        string sql = "delete from newMessage where id=" + id;
        if (dao.getComm(sql) != 0)
        {
            RegisterStartupScript("check", "<script language='javascript'>alert('记录已删除');</script>");
            show();
        }
        else
        {
            RegisterStartupScript("check", "<script language='javascript'>alert('对不起，删除失败');</script>");
        }
    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
       
        string id = this.GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
        Session["infoId"] = id;
        Server.Transfer("UpdateInfo.aspx");
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        show();
    }
}
